<?php

require 'Controller.php';
require './Home/Model/IndexModel.php';
header( 'Content-Type:text/html;charset=utf-8 ');

class IndexController extends Controller{

    function index(){
        $model= new IndexModel();
        $data=$model->getTypeList();
        $this->assign('Types',$data);
        $datarecentervideo=$model->getRecentList();
        $this->assign('recent',$datarecentervideo);
        $datahotvideo=$model->getHotList();
        $this->assign('hot',$datahotvideo);
        $this->display();
    }
    function choice(){
        $model= new IndexModel();
        $datarecentervideo=$model->getRecentList();
        $this->assign('recent',$datarecentervideo);
        $this->display();
    }
    function loginuser(){
        $this->display();
    }
    function videopage(){
        $vid=$_GET['vid'];
        $model= new IndexModel();
        $data=$model->getVideoAbout($vid);
        $this->assign('videos',$data);
        $this->display();
    }
    function videotypepage(){
        $tid=$_GET['tid'];
        $model= new IndexModel();
        $data=$model->getVideoFromType($tid);
        $this->assign('videos',$data);
        $this->display();
    }
    function search(){
        $search=$_POST['search'];
        $model= new IndexModel();
        $data = $model->searchVideo($search);
        $this->assign('searchv',$data);
        $this->display();
    }
    function login(){
        session_start();
        $username=$_POST['user'];
        $password=$_POST['password'];
        echo $username;
        echo $password;
        $model= new IndexModel();
        $result = $model->userLogin($username,$password);
        if ($result) {
            $_SESSION["user"]=$username;
            $_SESSION["password"]=$password;
            header("location:index.php?c=index&m=index");
        } else {
            echo "登陆失败！1秒后返回";
            header("refresh:1;url='index.php?c=index&m=index");
        }
    }
    function outlogin(){
        session_start();
        session_destroy();
        header("location:index.php?c=index&m=index");
    }


}
?>